package com.shqyang.yexplorer.manager;


import com.shqyang.yexplorer.ExplorerFragment;
import com.shqyang.yexplorer.util.LogManager;

import java.io.File;

/**
 * Created by Swsbty on 2021/05/22
 */
public class ExplorerManager {

    private boolean isSearchMode = false;
    private static ExplorerManager instance;
    public static ExplorerManager getInstance() {
        if (instance == null) {
            LogManager.d("not initialize!");
            return null;
        }
        return instance;
    }

    private ExplorerFragment explorerFragment;
    private ExplorerManager(ExplorerFragment fragment) {
        explorerFragment = fragment;
    }

    public static void initialize(ExplorerFragment fragment) {
        instance = new ExplorerManager(fragment);
    }

    public void setSearchMode() {
        if (isSearchMode) {
            return;
        }
        isSearchMode = true;
        explorerFragment.exitCheckMode();
        explorerFragment.hideEmptyNotice();
        explorerFragment.clearList();
        explorerFragment.hideRouteBar();
    }

    public void setExplorerMode() {
        if (!isSearchMode) {
            return;
        }
        isSearchMode = false;
        explorerFragment.exitCheckMode();
        explorerFragment.showRouteBar();
        explorerFragment.refreshUI();
    }

    public void addFileToList(File file) {
        if (!isSearchMode) {
            LogManager.d("is not search mode!");
            return;
        }
        explorerFragment.addToList(file);
    }

    public void clearList() {
        explorerFragment.clearList();
    }

    public int getListSize() {
        return explorerFragment.getFileListSize();
    }
}
